#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010, M = 10010;
int dist[N], g[N][N], dis[N];
bool st[N];
int n, m;

int dijkstra() {
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    for (int i = 1; i <= n; ++i) {
        int t = -1;
        for (int j = 1; j <= n; ++j) {
            if (!st[j] && (t == -1 || dist[j] < dist[t])) {
                t = j;
            }
        }

        st[t] = true;
        for (int j = 1; j <= n; ++j) {
            dist[j] = min(dist[j], dist[t] + g[t][j]);
        }
    }
    return dist[n];
}

int main() {

    memset(g, 0x3f, sizeof g);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> dis[i];
    dis[n] = 0;
    for (int i = 1; i <= m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a][b] = c + dis[b];
        g[b][a] = c + dis[a];
    }
    cout << dijkstra();
    return 0;
}